/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class LargestTriangleArea {
	public double largestTriangleArea(int[][] points) {
		double max = 0;
		for (int i = 0; i < points.length; i++) {
			for (int j = i + 1; j < points.length; j++) {
				for (int k = j + 1; k < points.length; k++) {
					double a = getArea(points[i], points[j], points[k]);
					// System.out.println("_" + a);
					if (a > max) {
						max = a;
					}
				}
			}
		}
		return max;
	}

	private double getArea(int[] p1, int[] p2, int[] p3) {
		double res = 0.5 * (p1[0] * (p2[1] - p3[1]) + p2[0] * (p3[1] - p1[1]) + p3[0] * (p1[1] - p2[1]));
		if (res < 0) {
			return -res;
		}
		return res;
	}

	public static void main(String[] args) {
		int[][] points = { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, 2 }, { 2, 0 } };
		System.out.println(new LargestTriangleArea().largestTriangleArea(points));
	}
}
